package com.miaow.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @author HWZ
 * @date 2023年12月19日 19:32
 * @description
 */
@Component
public class CustomFilter extends ZuulFilter {
    @Override
    public String filterType() {
        return "pre"; // 过滤器类型，可以是pre、route、post、error
    }

    @Override
    public int filterOrder() {
        return 1; // 过滤器执行顺序，数值越小越先执行
    }

    @Override
    public boolean shouldFilter() {
        return true; // 是否启用该过滤器
    }

    @Override
    public Object run() {
        // 过滤器逻辑
        RequestContext ctx = RequestContext.getCurrentContext();
        HttpServletRequest request = ctx.getRequest();
        System.out.println("Request Method : " + request.getMethod() + " Request URL : " + request.getRequestURL().toString());
        return null;
    }
}
